from sqlalchemy import Column, String, Boolean
from sqlalchemy.orm import relationship
from app.models import BaseModel
from app.models.role import user_role

class User(BaseModel):
    """用户模型"""
    __tablename__ = "users"
    
    username = Column(String(50), unique=True, index=True, nullable=False, comment="用户名")
    email = Column(String(100), unique=True, index=True, nullable=False, comment="邮箱")
    password = Column(String(100), nullable=False, comment="密码（已加密）")
    is_active = Column(Boolean, default=True, comment="是否激活")
    
    # 与Role模型建立多对多关系
    roles = relationship("Role", secondary=user_role, back_populates="users")
